 *************
 * Raw Figures
 *************
 
 clear all
 use "/Users/adansilverio/Dropbox/Paper 50 Terremotos/DataN/BaseProyecto.dta"
 keep if ano==2017 | ano==2018
 
 * S1: Generate time
 
  tab mes ano
  gen month=.
  replace month=-8 if mes==1 & ano==2017 
  replace month=-7 if mes==2 & ano==2017  
  replace month=-6 if mes==3 & ano==2017  
  replace month=-5 if mes==4 & ano==2017  
  replace month=-4 if mes==5 & ano==2017  
  replace month=-3 if mes==6 & ano==2017  
  replace month=-2 if mes==7 & ano==2017  
  replace month=-1 if mes==8 & ano==2017  
  replace month=0 if mes==9 & ano==2017  
  replace month=1 if mes==10 & ano==2017  
  replace month=2 if mes==11 & ano==2017 
  replace month=3 if mes==12 & ano==2017  
  
  replace month=4 if mes==1 & ano==2018 
  replace month=5 if mes==2 & ano==2018  
  replace month=6 if mes==3 & ano==2018  
  replace month=7 if mes==4 & ano==2018  
  replace month=8 if mes==5 & ano==2018  
  replace month=9 if mes==6 & ano==2018  
  replace month=10 if mes==7 & ano==2018  
  replace month=11 if mes==8 & ano==2018  
  replace month=12 if mes==9 & ano==2018 
  
  replace month=13 if mes==10 & ano==2018 
  replace month=14 if mes==11 & ano==2018 
  replace month=15 if mes==12 & ano==2018 
  
  
  tab month, m
  
  save "/Users/adansilverio/Dropbox/Paper 50 Terremotos/DataN/BaseProyecto.dta", replace
  
  
  * S2. Prepare data for "treatment" and "control". In this case these variables are given by "earthquake"
  
  clear all
  use "/Users/adansilverio/Dropbox/Paper 50 Terremotos/DataN/BaseProyecto.dta"
  keep if  earthquake==1
  collapse Amenazast Lesionest RoboVeht RoboCasat DanoPropt , by (month)
  save "/Users/adansilverio/Dropbox/Paper 50 Terremotos/DataN/RawDataTerremotos_1.dta"
  
  
  use "/Users/adansilverio/Dropbox/Paper 50 Terremotos/DataN/BaseProyecto.dta"
  keep if  earthquake==0
  collapse Amenazast Lesionest RoboVeht RoboCasat DanoPropt, by (month)
  rename Amenazast AmenazastC
  rename Lesionest LesionestC
  rename RoboVeht RoboVehtC
  rename RoboCasat RoboCasatC
  rename DanoPropt DanoProptC
  
  save "/Users/adansilverio/Dropbox/Paper 50 Terremotos/DataN/RawDataTerremotos_2.dta"
  
   use "/Users/adansilverio/Dropbox/Paper 50 Terremotos/DataN/RawDataTerremotos_1.dta"
   merge 1:1 month using "/Users/adansilverio/Dropbox/Paper 50 Terremotos/DataN/RawDataTerremotos_2.dta"
   save "/Users/adansilverio/Dropbox/Paper 50 Terremotos/DataN/RawDataTerremotos.dta"
   
   
   
   
   
    * S3.  Prepare Graphs
  clear all
  use "C:\Users\jose.balmori\Universidad Anahuac Dropbox\Jose Balmori\Paper 50 Terremotos\DataN\RawDataTerremotos.dta"
  cd "C:\Users\jose.balmori\Universidad Anahuac Dropbox\Jose Balmori\Paper 50 Terremotos\PaperN\output"
  
  sum Amenazast Lesionest RoboVeht RoboCasat DanoPropt
  
  * Amenazast
 
  label var Amenazast  "Impacted"
  label var AmenazastC "Not impacted"
  
  grstyle init
  grstyle set plain 
  grstyle set lpattern solid  longdash     
  grstyle set linewidth  medthick  medthick 
  grstyle set color  black blue  
  grstyle set symbol  i i 
  
  twoway connected Amenazast  AmenazastC month,  xtitle("Months since the earthquake") xline(0) xlabel(-8(1)12) ytitle("Crimes per 100,000 inhabitants") ylabel(0.0(1.0)7.0) title("Assault") 
  
  graph save Raw1, replace
  
  * Lesionest
 
  label var Lesionest  "Impacted"
  label var LesionestC "Not impacted"
  
  grstyle init
  grstyle set plain 
  grstyle set lpattern solid  longdash     
  grstyle set linewidth medthick  medthick  
  grstyle set color  black blue  
  grstyle set symbol  i i 
  
  twoway connected Lesionest  LesionestC month,  xtitle("Months since the earthquake") xline(0) xlabel(-8(1)12) ytitle("Crimes per 100,000 inhabitants") ylabel(0.0(1.0)7.0) title("Aggravated Assault") 
  
  graph save Raw2, replace
  
  
  * RoboVeht
 
  label var RoboVeht  "Impacted"
  label var RoboVehtC "Not impacted"
  
  grstyle init
  grstyle set plain 
  grstyle set lpattern solid  longdash     
  grstyle set linewidth medthick  medthick 
  grstyle set color  black blue  
  grstyle set symbol  i i 
  
  twoway connected RoboVeht  RoboVehtC month,  xtitle("Months since the earthquake") xline(0) xlabel(-8(1)12) ytitle("Crimes per 100,000 inhabitants") ylabel(0.0(1.0)7.0) title("Vehicle Theft") 
  
  graph save Raw3, replace
  
  * RoboCasat
  sum RoboCasat RoboCasatC
  label var RoboCasat  "Impacted"
  label var RoboCasatC "Not impacted"
  
  grstyle init
  grstyle set plain 
  grstyle set lpattern solid  longdash     
  grstyle set linewidth medthick  medthick 
  grstyle set color  black blue  
  grstyle set symbol  i i 
  
  twoway connected RoboCasat  RoboCasatC month,  xtitle("Months since the earthquake") xline(0) xlabel(-8(1)12) ytitle("Crimes per 100,000 inhabitants") ylabel(0.0(1.0)7.0) title("Residential Burglary") 
  
  graph save Raw4, replace
  
  
  * DanoPropt
  sum DanoPropt DanoProptC
  label var DanoPropt  "Impacted"
  label var DanoProptC "Not impacted"
  
  grstyle init
  grstyle set plain 
  grstyle set lpattern solid  longdash     
  grstyle set linewidth medthick  medthick  
  grstyle set color  black blue  
  grstyle set symbol  i i 
  
  twoway connected DanoPropt  DanoProptC month,  xtitle("Months since the earthquake") xline(0) xlabel(-8(1)12) ytitle("Crimes per 100,000 inhabitants") ylabel(0.0(1.0)7.0) title("Vandalism") 
  
  graph save Raw5, replace
  
  * Junta las graficas
  *set scheme s2color
  grc1leg  Raw1.gph Raw2.gph Raw3.gph   Raw4.gph Raw5.gph      ///
, iscale(.5) col(2)    imargin(0 0 0 0 ) name(g8, replace)  
graph display g8, xsize(6) ysize(8)
graph export "C:\Users\jose.balmori\Universidad Anahuac Dropbox\Jose Balmori\Paper 50 Terremotos\PaperN\output\RawV2.png", as(png) width(1000) replace

 
  
  